package org.tech4j.springboot.starter.captcha.graphical;

import org.tech4j.captcha.api.model.CaptchaResponse;
import org.tech4j.captcha.graphical.builder.GraphicalCaptchaEntityBuilder;
import org.tech4j.captcha.graphical.factory.GraphicalCaptchaEntityBuilderFactory;
import org.tech4j.captcha.graphical.service.CaptchaService;

/**
 * @program: tech4j
 * @description:
 * @author: YuKai Fan
 * @create: 2025/3/5 09:15
 **/
public class CaptchaServiceFactory {

    private static CaptchaService captchaService;
    private CaptchaServiceFactory() {
    }

    public static CaptchaResponse getCaptcha(String captchaType, String key, String storeType, Long expireAt) {
        GraphicalCaptchaEntityBuilder captchaEntityBuilder = GraphicalCaptchaEntityBuilderFactory.newInstance(captchaType);
        return captchaService.getCaptcha(captchaEntityBuilder.buildCaptchaEntity(key, storeType, expireAt));
    }

    public static CaptchaResponse checkCaptcha(String captchaType, String key, String storeType, String pointValue, Long expireAt) {
        GraphicalCaptchaEntityBuilder captchaEntityBuilder = GraphicalCaptchaEntityBuilderFactory.newInstance(captchaType);
        return captchaService.checkCaptcha(captchaEntityBuilder.buildCheckCaptchaEntity(key, storeType, pointValue, expireAt));
    }

    public static CaptchaResponse verification(String captchaType, String key, String storeType) {
        GraphicalCaptchaEntityBuilder captchaEntityBuilder = GraphicalCaptchaEntityBuilderFactory.newInstance(captchaType);
        return captchaService.verification(captchaEntityBuilder.buildVerifyCaptchaEntity(key, storeType));
    }

    public static void setCaptchaService(CaptchaService captchaService) {
        CaptchaServiceFactory.captchaService = captchaService;
    }
}
